<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: address_book.php 151 2013-09-22 07:52:11Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 151 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-22 07:52:11 +0000 (Sun, 22 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

include ('includes/application_top.php');

$smarty = new Smarty;
require (DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/source/boxes.php');
require_once (DIR_FS_INC.'inc.address_label.php');
require_once (DIR_FS_INC.'inc.get_country_name.php');
require_once (DIR_FS_INC.'inc.count_customer_address_book_entries.php');

if(!isset($_SESSION['customer_id']))
	redirect(href_link(FILENAME_LOGIN, '', 'SSL'));

$breadcrumb->add(NAVBAR_TITLE_1_ADDRESS_BOOK, href_link(FILENAME_ACCOUNT, '', 'SSL'));
$breadcrumb->add(NAVBAR_TITLE_2_ADDRESS_BOOK, href_link(FILENAME_ADDRESS_BOOK, '', 'SSL'));

require (DIR_WS_INCLUDES.'header.php');

$smarty->assign('ADDRESS_DEFAULT', address_label($_SESSION['customer_id'], $_SESSION['customer_default_address_id'], true, ' ', '<br />'));

$addresses_data = array();
$addresses	= $db->db_query("SELECT 
								address_book_id, 
								entry_firstname AS firstname, 
								entry_lastname AS lastname, 
								entry_company AS company, 
								entry_street_address AS 
								street_address, 
								entry_suburb AS suburb, 
								entry_city AS city, 
								entry_postcode AS postcode, 
								entry_state AS state, 
								entry_zone_id AS zone_id, 
								entry_country_id AS country_id 
							FROM 
								".TABLE_ADDRESS_BOOK." 
							WHERE 
								customers_id = '".(int) $_SESSION['customer_id']."' 
							ORDER BY 
								firstname, 
								lastname");

while (!$addresses->EOF) {
	$format_id = get_address_format_id($addresses->fields['country_id']);
	if ($addresses->fields['address_book_id'] == $_SESSION['customer_default_address_id']) {
		$primary = 1;
	} else {
		$primary = 0;
	}
	$addresses_data[] = array('NAME' => $addresses->fields['firstname'].' '.$addresses->fields['lastname'], 
								'BUTTON_EDIT' => '<a href="'.href_link(FILENAME_ADDRESS_BOOK_PROCESS, 'edit='.$addresses->fields['address_book_id'], 'SSL').'">'.image_button('small_edit.gif', SMALL_IMAGE_BUTTON_EDIT).'</a>', 
								'BUTTON_DELETE' => '<a href="'.href_link(FILENAME_ADDRESS_BOOK_PROCESS, 'delete='.$addresses->fields['address_book_id'], 'SSL').'">'.image_button('small_delete.gif', SMALL_IMAGE_BUTTON_DELETE).'</a>', 
								'ADDRESS' => address_format($format_id, $addresses->fields, true, ' ', '<br />'), 
								'PRIMARY' => $primary);
	$addresses->MoveNext();
}
$smarty->assign('addresses_data', $addresses_data);

$smarty->assign('BUTTON_BACK', '<a href="'.href_link(FILENAME_ACCOUNT, '', 'SSL').'">'.image_button('button_back.gif', IMAGE_BUTTON_BACK).'</a>');

if (count_customer_address_book_entries() < MAX_ADDRESS_BOOK_ENTRIES) 
	$smarty->assign('BUTTON_NEW', '<a href="'.href_link(FILENAME_ADDRESS_BOOK_PROCESS, '', 'SSL').'">'.image_button('button_add_address.gif', IMAGE_BUTTON_ADD_ADDRESS).'</a>');

$smarty->assign('ADDRESS_COUNT', sprintf(TEXT_MAXIMUM_ENTRIES, MAX_ADDRESS_BOOK_ENTRIES));

$smarty->assign('language', $_SESSION['language']);
$smarty->caching = false;
$main_content = $smarty->fetch(CURRENT_TEMPLATE.'/module/address_book.html');

$smarty->assign('language', $_SESSION['language']);
$smarty->assign('main_content', $main_content);
$smarty->caching = false;
if (!defined('RM'))
	$smarty->loadFilter('output', 'note');
$smarty->loadFilter('output','trimwhitespace');
$smarty->display(CURRENT_TEMPLATE.'/index.html');
include ('includes/application_bottom.php');
?>